package com.wsse.common.tool;

import java.io.File;
import java.io.RandomAccessFile;


public class LogFactory {
	private static LogFactory log;
	private static File file;
	private static long filePointer=0;
	private LogFactory(){}
	public synchronized static LogFactory init(String path){
		if(EmptyTool.is(path))
			path="resource/logInfo.txt";
		if(log==null){
			file= FileTool.getFile(path, true);
			log=new LogFactory();
		}
		return log;
	}
	public synchronized static void info(String str){
		if(str==null)return;
		try {
//			System.out.println(str);
			RandomAccessFile raf=new RandomAccessFile(file, "rw");
			str+="\n";
			byte[] bytes=str.getBytes();
			raf.seek(filePointer);
			raf.write(bytes, 0, bytes.length);
			filePointer=raf.getFilePointer();
			raf.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
